package IO;

import java.io.File;
import java.util.Scanner;

public class IODemo12 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入搜索的文件名");
        String FileName=scanner.next();
        System.out.println("请输入文件路径");
        String rootPath=scanner.next();

        File rootfile=new File(rootPath);
        if (rootfile.isDirectory()){
            System.out.println("路径有误");
            return;
        }

        scanDir(rootfile,FileName);
    }

    private static void scanDir(File rootfile, String fileName) {
        File[] files=rootfile.listFiles();
        if (files==null){
            return;
        }
        for(File f:files){
            if (f.isFile()){
                if (fileName.equals(f.getName())){
                    System.out.println("找到了"+f.getAbsolutePath());
                }else if(f.isDirectory()){
                    scanDir(f,fileName);
                }else {
                    ;
                }
            }
        }
    }
}
